package com.study.demo.valid;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author liuhongzhen
 * @date 2022/4/25 20:16
 */
public class OptionalDemo {


    public static void main(String[] args) {

        PageSellDto dto = new PageSellDto();

        dto.setPageNo(1);
        dto.setPageSize(20);
        dto.setAuthState("1");
        dto.setGoodsState("1");
        dto.setFrozenState("1");

//        Optional.ofNullable(dto).ifPresent(d ->{
//            System.out.println("不为空才执行："+ d.getAuthState());
//        });

        Class<?> clazz = dto.getClass();  //得到类对象
        Field[] fs = clazz.getDeclaredFields(); //得到属性集合
        List list = new ArrayList();
        for(Field field:fs) {            //遍历属性
            field.setAccessible(true); //设置属性是可以访问的（私有的也可以）
            try {
                System.out.println(field.getName());
                System.out.println(field.get(dto));
            } catch (Exception e) {
                e.printStackTrace();
            }

        }
    }


    private static Pattern linePattern = Pattern.compile("_(\\w)");

    private static Pattern humpPattern = Pattern.compile("[A-Z]");


    public static String humpToLine(String str) {

        Matcher matcher = humpPattern.matcher(str);
        StringBuffer sb = new StringBuffer();
        while (matcher.find()) {
            matcher.appendReplacement(sb, "_" + matcher.group(0).toUpperCase());
        }
        matcher.appendTail(sb);
        return sb.toString().toLowerCase();

    }

//    public static void main(String[] args) {
//
//
//        String aa = humpToLine("shelveStartTime");
//
//        System.out.println(aa);
//    }
}
